package com.xx.news.viewmodel;

import android.app.Application;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import com.xx.news.base.BaseViewModel;
import com.xx.news.entity.Jingxuan;
import com.xx.news.repository.NewsRepository1;

import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;

public class YuleViewModel extends BaseViewModel {
    NewsRepository1 repository;
    private MutableLiveData<Jingxuan> jingxuans = new MutableLiveData<>();

    public YuleViewModel(@NonNull Application application) {
        super(application);
        setTitle("娱乐（数据和头条一样）");
        repository = new NewsRepository1();
    }

    public LiveData<Jingxuan> getLiveData() {
        return jingxuans;
    }


    public void getDate() {
        getUC().getShowDialogEvent().call();
        repository.getJingXuanData().subscribe(new Observer<Jingxuan>() {
            @Override
            public void onSubscribe(@io.reactivex.rxjava3.annotations.NonNull Disposable d) {
                Log.d("abcd", "onSubscribe");
            }

            @Override
            public void onNext(@io.reactivex.rxjava3.annotations.NonNull Jingxuan jingxuan) {
                Log.d("abcd", "onNext: " + jingxuan.toString());
                getUC().getDismissDialogEvent().call();
                jingxuans.postValue(jingxuan);
            }

            @Override
            public void onError(@io.reactivex.rxjava3.annotations.NonNull Throwable e) {
                Log.d("abcd", "onError");
            }

            @Override
            public void onComplete() {
                Log.d("abcd", "onComplete");
            }
        });
    }

}
